# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=freetype
pkgver=2.12.1
pkgrel=0
pkgdesc="TrueType font rendering library"
url="https://www.freetype.org/"
arch="all"
license="FTL GPL-2.0-or-later"
options="!check"
makedepends="
	brotli-dev
	bzip2-dev
	libpng-dev
	libx11-dev
	zlib-dev
	"
subpackages="
	$pkgname-static
	$pkgname-dev
	$pkgname-demos
	$pkgname-doc
	"
source="https://download.savannah.gnu.org/releases/freetype/freetype-$pkgver.tar.xz
	https://download.savannah.gnu.org/releases/freetype/ft2demos-$pkgver.tar.xz
	0001-Enable-table-validation-modules.patch
	subpixel.patch
	"

# secfixes:
#   2.12.1-r0:
#     - CVE-2022-27404
#   2.10.4-r0:
#     - CVE-2020-15999
#   2.9-r1:
#     - CVE-2018-6942
#   2.7.1-r1:
#     - CVE-2017-8105
#     - CVE-2017-8287

prepare() {
	default_prepare

	mv ../ft2demos-$pkgver ft2demos
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--enable-static \
		--with-brotli \
		--with-bzip2 \
		--with-png \
		--enable-freetype-config
	make
	make -C ft2demos TOP_DIR=".."
}

package() {
	make DESTDIR="$pkgdir" install
	make -C ft2demos TOP_DIR=".." DESTDIR="$pkgdir" install
}

demos() {
	pkgdesc="A collection of FreeType demos"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin
}

sha512sums="
6482de1748dc2cc01e033d21a3b492dadb1f039d13d9179685fdcf985e24d7f587cbca4c27ed8a7fdb7d9ad59612642ac5f4db062443154753295363f45c052f  freetype-2.12.1.tar.xz
cd9356152a64d807c75b797d005ca1dd0bde69cc2fadedec101d125cb54b2aaff1f7afa2f20839caba7db66325df7c11ed4883b7e906110356b28d9900caaae7  ft2demos-2.12.1.tar.xz
580fe59acddfd41966e387bdb6a88336b8bc119cc3d60d8689be20c96fb0dd07c5138ea31f6cb9c854f497ecb41c3adc49eb3ec16a34b2e010e8294851770763  0001-Enable-table-validation-modules.patch
72883fa203fd2552a7b1b8c39b4aaa68d407c62c289236031cd0fa1c8cdc6ad38e90d3b53f8ee682064986d09c9455961f4941c80566b150d15d5539a716c190  subpixel.patch
"
